package ltd.jdsoft.cute.perm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ltd.jdsoft.cute.cache.CacheClient;
import ltd.jdsoft.cute.cache.CacheKeyUtil;
import ltd.jdsoft.cute.cache.callback.GetCallback;
import ltd.jdsoft.cute.common.util.StrTool;
import ltd.jdsoft.cute.perm.dao.MenuDAO;
import ltd.jdsoft.cute.perm.model.Menu;

@Service
public class MenuService {

  public static final CacheKeyUtil keyUtil = new CacheKeyUtil(Menu.class);
  @Autowired
  private MenuDAO menuDAO;

  public List<Menu> getMenuList(String menuIds) {
    return CacheClient.get(keyUtil.getRecKey("." + menuIds), new GetCallback<List<Menu>>() {

      @Override
      public String getCacheGroup() {
        return null;
      }

      @Override
      public List<Menu> getObject() {
        List<Long> menuIdList = StrTool.stringToLongList(menuIds);
        return menuDAO.getMenuList(menuIdList);
      }
    });
  }
}
